﻿using Bll;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Web.PublicWeb;

namespace Web.Controllers
{
    public class DefaultController : Controller
    {
        SysUser sysUser = LoginCookie.GetUser();

        [Backstage_LoginExists()]
        public ActionResult Default()
        {
            ViewBag.Menu = MenuLoad(sysUser.TRoleId);
            return View();
        }

        public string MenuLoad(int RoleId)
        {
            StringBuilder builderString = new StringBuilder();
            var bll = new MenuBll();
            var list = bll.GetMenuByRoleId(RoleId);
            if (list.Count > 0)
            {
                int pMenuSum = 0;//父菜单项的总个数
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].PId == 0)
                    {
                        pMenuSum++;
                        builderString.Append("<li onclick=\"show(" + pMenuSum + ")\" class=\"menu-CP\"><img src=\"/css/image/tubiao_34.png\"/><div class=\"gongneng1\">" + list[i].MenuName + "</div></li>");
                        ///////////////     a标签作为内容的li   ///////////////

                        #region a标签作为内容的li
                        if (pMenuSum == 1)//第一个需要展开
                        {
                            builderString.Append("<li id=\"menulist" + pMenuSum + "\" class=\"erjicaidan\">");
                        }
                        else
                        {
                            builderString.Append("<li id=\"menulist" + pMenuSum + "\" class=\"erjicaidan_none\">");
                        }

                        for (int j = 0; j < list.Count; j++)
                        {
                            if (list[j].PId == list[i].MenuId)
                            {
                                builderString.Append("<a target=\"mainbox\" class=\"erjicaidan-2\" href=\"" + list[j].MenuPath + "\">" + list[j].MenuName + "</a>");
                            }
                        }

                        builderString.Append("</li>");
                        #endregion
                    }
                }
                builderString.Append("<script>var iteams=" + pMenuSum + ";  </script>");
            }

            return builderString.ToString();
        }
    }
}
